package com.mvp.lt.airlineview.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.StyleRes;

import com.mvp.lt.airlineview.R;


/**
 * 自定义内容Dialog
 */
public class BaseDialog extends Dialog {
    private int resLayoutId;

    public BaseDialog(Context context, int resLayoutId) {
        super(context, R.style.base_customDialog);
        this.resLayoutId = resLayoutId;
        Window window = getWindow();
        window.setWindowAnimations(R.style.base_BaseDialogWindowStyle);
    }
    public BaseDialog(Context context, int resLayoutId, @StyleRes int themeResId) {
        super(context, themeResId);
        this.resLayoutId = resLayoutId;
        Window window = getWindow();
        window.setWindowAnimations(R.style.base_BaseDialogWindowStyle);
    }
    public void setDCancelable(boolean flag) {
        setCancelable(flag);
        setCanceledOnTouchOutside(flag);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(resLayoutId);
    }


    @Override
    public void show() {
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        super.show();
        fullScreenImmersive(getWindow().getDecorView());
        this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    }

    private void fullScreenImmersive(View view) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_FULLSCREEN;
            view.setSystemUiVisibility(uiOptions);
        }
    }
}